Troubleshooting Scripting

This topic covers the troubleshooting steps that you face while working with Scripting.

Scripts Are Not Running

If you face any issue while running a script, follow the steps below to identify and resolve common problems related to trigger configuration and script deployment.

  • Check Script Status - Ensure the script is in Published state. Only the published scripts can be linked to policies and executed.
  • Verify Trigger Configuration - Confirm that a trigger is configured (After device starts, After user logon, On a schedule). For scheduled triggers, ensure a valid 24-hour format time is set and repetition settings are correct.
  • Check Deployment Status - Review the script's deployment status in the device policy section.
    • Purple color indicates in-progress
    • Red color indicates failure
    • Green color indicates successful deployment.
  • Look for 'Awaiting Trigger' Status - If the script is deployed but not running, check if the job is in Awaiting Trigger state, indicating it is waiting for the next scheduled execution.
  • Review Script Edits - If the script was edited (for example, trigger time changed), you must push the changes to update the deployed script. The previous job will be marked as completed and a new job created.
  • Confirm Platform and Language Support - Ensure the script type is supported on the target OS. For example, PowerShell and Windows Batch for Windows, PowerShell and POSIX for macOS.
  • Check Logs and History - Review execution history and logs for errors or skipped runs. This helps identify issues like missing inputs or permission errors.
    To investigate further, review the following KACE Cloud log files based on your operating system:
    Folder/File NameDescriptionLocation of the File
    Windows  

    cloudscript plugin log

    Logging specific to cloudscript plugin, includes syncing with KACE CloudC:\ProgramData\Quest\KACECloud\logs\cloudscript.log
    kacecloud.logLogging specific to KACE Cloud agent communicationC:\ProgramData\Quest\KACECloud\logs\kacecloud.log
    Script cache folder Look for <guid> folder. It is a folder containing each script file and dependenciesC:\ProgramData\Quest\KACECloud\cloudscript\cache
    Script execution output logLook for files named ScriptFileName-<guid>.log where <guid> is unique for each script run. /Library/Application Support/Quest/KACECloud/data/cloudscript/log
    macOS  
    cloudscript plugin log Logging specific to cloudscript plugin, includes syncing with KACE Cloud /Library/Application Support/Quest/KACECloud/data/logs/cloudscript.log
    KACE Cloud Agent Communication LogCaptures communication between macOS agent and KACE Cloud/Library/Application Support/Quest/KACECloud/data/logs/kacecloud.log
    Script Cache Folder

    Look for the <guid> folder. The <guid> is unique for each script.

    The folder contains each script file and its dependencies.

    /Library/Application Support/Quest/KACECloud/data/cloudscript/cache
    Script Execution output LogLook for files named ScriptFileName-<guid>.log. The <guid> is unique for each script run. These logs capture the output of each script execution./Library/Application Support/Quest/KACECloud/data/cloudscript/log

 

Script Failure Not Reflected in Logs or UI

PowerShell scripts may return an exit code of 0 (success) even when an error or exception occurs. This happens because PowerShell.exe does not automatically exit with a non-zero status when a script encounters an error. As a result:

  • The script failure is not indicated in logs (exit: 0).
  • The UI incorrectly displays the command as Passed instead of Failed.

Causes: The causes are:

  • The script does not explicitly handle exceptions and return a non-zero exit code.
  • PowerShell's default behavior does not change the exit status unless specified.

Solution:

To ensure that script failures are properly reported in logs and UI, modify the script to include error handling and explicitly exit with a non-zero code.

Recommendations:

  • Always include exception handling in scripts.
  • Use exit <non-zero-code> to ensure failures are correctly reported in logs and UI.
  • Review logs (`cloudscript/logs`) to verify the script’s exit code.

Example of the Scripts

 

Script (No Error Handling)
UI Status: Passed

Script (With Error Handling)
UI Status: Failed

Script

 $number = 1 / 0 

try {

   $number = 1 / 0

} catch {

 Write-Host "Error occurred: $_"  

exit 1  # Ensures PowerShell exits with error code 1

}

Logs Output

{ "ts": "2025-01-29T12:40:03Z", "src": "stderr",   "msg": " + CategoryInfo: NotSpecified: (:) [], RuntimeException" },

{ "ts": "2025-01-29T12:40:03Z", "src": "stderr",   "msg": " + FullyQualifiedErrorId : RuntimeException" },

{ "ts": "2025-01-29T12:40:03Z", "src": "stderr",   "msg": " " },

{ "ts": "2025-01-29T12:40:04Z", "src": "agent",    "msg": "Script Result: succeeded"  } ],

"ts": "2025-01-29T12:40:04Z",

"result": "succeeded",

"exit": 0,

"hex": "0"

}

{

"id": "23f5153578434ef88eeb56b581e12162",

"version": "31",

"run": "31",

"log": [{  "ts": "2025-01-30T05:39:41Z", "src": "stdout", "msg": "Error occurred: Attempted to divide by zero."     },

{  "ts": "2025-01-30T05:39:45Z", "src": "agent",  "msg": "Script Result: failed - exit status 1"     }],

"ts": "2025-01-30T05:39:45Z",

"result": "failed",

"exit": 1,

"hex": "1"

}

Script fails to run or Dependencies do not validate

If your script fails to run or dependencies do not validate, review the troubleshooting section below for common errors and resolutions.

Error Description Resolution
Checksum verification failed Incorrect checksum added. Regenerate checksum from the exact dependency file. Add the correct checksum.
Download failed: File Not found Invalid location or file moved to other location. Verify the URL or the path and update the dependency.
Script execution failed One or more dependencies are invalid. Review and fix all the dependencies added or remove the unused dependency files with error.